<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>在线投票系统-后台登录</title>
		<link rel="stylesheet" href="../css/layui.css" />
		<link rel="stylesheet" href="../css/web/common.css" />
		<link rel="stylesheet" href="../css/web/login.css" />
	</head>

	<body>
		<div class="layui-container">
			<div class="layadmin-user-login-main center">
				<form id="login" class="layadmin-user-login-box layadmin-user-login-body layui-form">
					<div class="layui-form-item">
						<div class="logo">
							<img src="https://spring.io/img/homepage/icon-spring-cloud-data-flow.svg" />
						</div>
						<h3 class="title">在线投票后台管理系统欢迎您</h3>
					</div>
					<div class="layui-form-item">
						<input name="username" lay-verify="required" placeholder="Username" class="my-layui-input" type="text">
					</div>
					<div class="layui-form-item">
						<input name="password" lay-verify="required|password" placeholder="Password" class="my-layui-input" type="password">
					</div>
					<div class="layui-form-item">
						<button class="my-layui-btn" lay-submit lay-filter="LAY-user-login-submit">确认登录</button>
					</div>
				</form>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../layui.js"></script>
	<script type="text/javascript" src="../lay/system/admin/public.js"></script>
	<script type="text/javascript">
		layui.use(['layer', 'form', 'element'], function() {
			var layer = layui.layer,
				element = layui.element,
				form = layui.form,
				$ = layui.$;
			form.render();
			//提交
			form.on('submit(LAY-user-login-submit)', function(data) {
				var user_data = JSON.stringify(data.field);
				$.ajax({
					url: IP + '/api/admin/login',
					contentType: "application/x-www-form-urlencoded",
					data: $('#login').serialize(),
					success: function(result, status, xhr) {
						localStorage.setItem("token", result.data.token);
						layer.closeAll('loading');
						layer.msg("登录成功", {
							icon: 1,
							time: 1000
						}, function() {
							parent.window.location.href = 'index.html'
						});
					}
				});
				return false;
			});
			form.verify({
				password: [
					/^[\S]{5,12}$/, '密码必须5到12位，且不能出现空格'
				]
			});
			$(function() {
				$('#test').click(function() {
					refresh_token();
				})
			})
		});
	</script>
	<script>
	</script>

</html>